package uk.co.beetec.android.npvrui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class NPvrUiSettingsActivity extends Activity
	implements OnClickListener {

	EditText server_name_editText = null;
	EditText server_url_wifi_editText = null;
	EditText server_port_editText = null;
	EditText server_html_file_editText = null;
	Button save_Button = null;
	Button cancel_Button = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);

		server_name_editText = (EditText) findViewById(R.id.server_name_editText);
		server_url_wifi_editText = (EditText) findViewById(R.id.server_url_wifi_editText);
		server_port_editText = (EditText) findViewById(R.id.server_port_editText);
		server_html_file_editText = (EditText) findViewById(R.id.server_html_file_editText);

		server_name_editText.setText("Default");

		save_Button = (Button) findViewById(R.id.saveButton);
		cancel_Button = (Button) findViewById(R.id.cancelButton);
		save_Button.setOnClickListener(this);
		cancel_Button.setOnClickListener(this);
	}

	@Override
	public void onClick(View view) {
		if (view.equals(save_Button)) {
			String server_url_wifi = server_url_wifi_editText.getText().toString();
			String server_port = server_port_editText.getText().toString();
			String server_html_file = server_html_file_editText.getText().toString();
			SharedPreferences prefs = getSharedPreferences("npvrui", MODE_PRIVATE);
			prefs.edit().putString("npvruiServerAddress", server_url_wifi).commit();
			prefs.edit().putString("npvruiPort", server_port).commit();
			prefs.edit().putString("npvruiHtmlFile", server_html_file).commit();
        	Intent i = new Intent(this, NPvrUiActivity.class);
        	startActivity(i);
		}
		finish();
	}
}
